package com.ruikong.dazhi.config;

import com.ruikong.dazhi.dao.base.PersonnelMapper;
import com.ruikong.dazhi.dao.base.RoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CpiInterceptor implements HandlerInterceptor {

    //人员用户
    @Autowired
    private PersonnelMapper personnelMapper;

    //角色
    @Autowired
    private RoleMapper roleMapper;



    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        Object session = request.getSession().getAttribute("userId");
        if (session == null) {
            response.sendRedirect(request.getContextPath() + "/");
            return false;
        } else {
            return true;
        }
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
    }
}
